export default {
    inserted: function (el, binding, vnode) {

        let childEl = null
        el.childNodes.forEach(item => {
            if (item.className === 'shadow-empty') {
                childEl = item
            }
        })
        binding.value ? childEl && childEl.parentNode.removeChild(childEl) : append(el, binding)
    },
    componentUpdated: function (el, binding, vnode) {
        let childEl = null
        /** 数据更新时出现重复添加空标签 */
        let flag = false
        el.childNodes.forEach(item => {
            if (item.className === 'shadow-empty') {
                flag = true
                childEl = item
            }
        })
        if (flag && !binding.value) return
        binding.value ? childEl && childEl.parentNode.removeChild(childEl) : append(el, binding)
    }
}

const append = function (el, binding) {
    let emptyEl = document.createElement('div')
    emptyEl.setAttribute('class', 'shadow-empty')
    emptyEl.innerText = '暂无数据'
    el.appendChild(emptyEl)
}
